import { useDidShow, useRouter } from '@tarojs/taro'
import { uuid } from "uuid";
import 'core-js'
import { home } from './home';
import './app.scss'
import { common } from './state';
import { EventBus } from "ts-simple-event-bus";
import EventBusContext from './evnetbus';
import { useEffect } from 'react';

import VConsole from 'vconsole';
import { View } from '@tarojs/components';


const App = ({ children }) => {
  const router = useRouter()


  // const vConsole = new VConsole();
  // 或者使用配置参数来初始化，详情见文档

  //声明全局的

  type EventBusTyping = {
    queue: {
      a: string;
      b: number;
    }
  };

  // useDidShow(async () => {
  //   bus.subscribe({ queue: "queue", callback: (message) => {
  //     console.log(message.id, message.a, message.b);
  //   } });
  //   const socketTask = Taro.connectSocket({
  //     url: 'ws://47.96.138.184:8282'
  //   });
  //   (await socketTask).onMessage(callback => {
  //     console.log("--------")
  //     bus.publish({ queue: "queue", message: { a: "a", b: 1 } });

  //   })

  // })

  useEffect(() => {
    // var overscroll = function (el) {
    //   el.addEventListener('touchstart', function () {
    //     var top = el.scrollTop
    //       , totalScroll = el.scrollHeight
    //       , currentScroll = top + el.offsetHeight;
    //     //If we‘re at the top or the bottom of the containers
    //     //scroll, push up or down one pixel.
    //     //
    //     //this prevents the scroll from "passing through" to
    //     //the body.
    //     if (top === 0) {
    //       el.scrollTop = 1;
    //     } else if (currentScroll === totalScroll) {
    //       el.scrollTop = top - 1;
    //     }
    //   });
    //   el.addEventListener('touchmove', function (evt) {
    //     //if the content is actually scrollable, i.e. the content is long enough
    //     //that scrolling can occur
    //     if (el.offsetHeight < el.scrollHeight)
    //       evt._isScroller = true;
    //   });
    // }
    // overscroll(document.querySelector('.scroll'));
    // document.body.addEventListener('touchmove', function (evt) {
    //   //In this case, the default behavior is scrolling the body, which
    //   //would result in an overflow.  Since we don‘t want that, we preventDefault.
    //   if (!evt._isScroller) {
    //     evt.preventDefault();
    //   }
    // });
  }, [])

  return (

    <View>
      {children}
    </View>
  )
}

export default App
